package com.example.projectcode.controller.Admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.projectcode.model.Administrater;
import com.example.projectcode.model.Student;
import com.example.projectcode.result.Result;
import com.example.projectcode.service.AdministraterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "后台管理员接口")
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdministraterService administraterService;


    /*----------------------管理员个人信息管理------------------------------------------*/

    @ApiOperation("添加管理员")
    @PostMapping("/insertAdministrater")
    public Result insertSutdent(@RequestBody Administrater administrater)
    {
        if(administraterService.insertAdministrater(administrater)){
            //添加成功
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    @ApiOperation("分页查询管理员")
    @GetMapping("/listAdministrater/{current}/{size}")
    public Result listStudent(@PathVariable long current,@PathVariable long size){
        Page<Administrater> page1 = new Page<>(current,size);
        IPage<Administrater> iPage = administraterService.page(page1,null);
        return Result.ok(iPage);
    }

    @ApiOperation("根据管理员id删除管理员")
    @GetMapping("/deleteAdministrater/{id}")
    public Result deleteAdministrater(@PathVariable Integer id){
        if(administraterService.deleteAdministraterById(id)>0){
            return Result.ok();
        }
        return Result.fail();
    }

    @ApiOperation("根据管理员id修改个人信息")
    @PostMapping("updateAdministrater")
    public Result updateStudent(@RequestBody Administrater administrater){
        if(administraterService.updateStudent(administrater)>0)
            return Result.ok();
        return Result.fail();
    }


}
